<template>
	<view>
		<view class='item' v-for="(item,i) in goodsList" :key='i'>
			<view @tap="gotodetails(item)">
				<image :src="item.goods_big_logo" mode=""></image>
				<text>{{item.goods_name}}</text><br>
				<text style='color: red;'>{{item.goods_price}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				queryOptions: {
					query: '',
					cid: '',
					pagenum: 1,
					pagesize: 10
				},
				goodsList: [],
				total: 0
			};
		},
		onLoad(options) {
			console.log(options);
			this.queryOptions.query = options.query || ''
			this.queryOptions.cid = options.cid || ''
			this.getGoodsList()
		},
		methods: {
			async getGoodsList() {
				const { data: res } = await uni.$http.get('public/v1/goods/search', this.queryOptions)
				console.log(res);
				if (res.meta.status !== 200) return uni.$showMsg()
				this.goodsList = [...this.goodsList, ...res.message.goods]
				this.total = res.message.total
			},
			gotodetails(goods) {
				uni.navigateTo({
					url: '/subpkg/goods_detail/goods_detail?goods=' + goods.goods_id
				})
			}
		},
		onReachBottom() {
			this.queryOptions.pagenum++
			this.getGoodsList()
		}
	}

</script>

<style lang="scss">
	.item {
		height: 110px;

		image {
			width: 100px;
			height: 100px;
			float: left;
			margin-right: 20px;
		}

		text:nth-of-type(1) {
			font-size: 12px;
		}

	}

</style>

